home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / DirectPlay / Maze / MazeCommon / Packets.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-31  |  5.4 KB  |  189 lines

  1. //----------------------------------------------------------------------------
  2. // File: packets.h
  3. //
  4. // Desc: see main.cpp
  5. //
  6. // Copyright (c) 1999-2001 Microsoft Corp. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. #ifndef _PACKETS_H
  9. #define _PACKETS_H
  10.  
  11. #include "Trig.h"
  12.  
  13. #pragma pack(push)
  14. #pragma pack(1)
  15.  
  16. #define PACK_ARRAY_SIZE     10     //Set the number of elements in our pack array to 10.
  17.  
  18.  
  19. //-----------------------------------------------------------------------------
  20. // Name: 
  21. // Desc: 
  22. //-----------------------------------------------------------------------------
  23. enum
  24. {
  25.     PACKETTYPE_SERVER_CONFIG,       // first packet sent 
  26.     PACKETTYPE_CLIENT_VERSION,      // client responds to PACKETTYPE_SERVER_CONFIG w/ this 
  27.     PACKETTYPE_SERVER_ACKVERSION,   // server then responds to PACKETTYPE_CLIENT_VERSION w/ this and game begins
  28.     PACKETTYPE_CLIENT_POS,          // sent to server as client moves
  29.     PACKETTYPE_SERVER_ACKPOS        // sent to client as server acks the PACKETTYPE_CLIENT_POS packets
  30. };
  31.  
  32.  
  33.  
  34.  
  35. //-----------------------------------------------------------------------------
  36. // Name: 
  37. // Desc: Base class for packets sent from client to server
  38. //-----------------------------------------------------------------------------
  39. struct  ClientPacket
  40. {
  41.     ClientPacket();
  42.     ClientPacket( WORD type ) :
  43.         wType(type) {};
  44.  
  45.     WORD    wType;
  46. };
  47.  
  48.  
  49.  
  50.  
  51. //-----------------------------------------------------------------------------
  52. // Name: 
  53. // Desc: 
  54. //-----------------------------------------------------------------------------
  55. struct  ClientPosPacket : public ClientPacket
  56. {
  57.     ClientPosPacket();
  58.     ClientPosPacket( float x , float y, ANGLE cameraYaw )
  59.         : ClientPacket( PACKETTYPE_CLIENT_POS ) , fX(x) , fY(y), aCameraYaw(cameraYaw) {};
  60.  
  61.     float   fX,fY;  
  62.     ANGLE   aCameraYaw;
  63. };
  64.  
  65.  
  66.  
  67.  
  68. //-----------------------------------------------------------------------------
  69. // Name: 
  70. // Desc: 
  71. //-----------------------------------------------------------------------------
  72. struct  ClientVersionPacket : public ClientPacket
  73. {
  74.     ClientVersionPacket();
  75.     ClientVersionPacket( DWORD version )
  76.         : ClientPacket( PACKETTYPE_CLIENT_VERSION ) , dwVersion(version) {};
  77.  
  78.     DWORD dwVersion;  
  79. };
  80.  
  81.  
  82.  
  83.  
  84. //-----------------------------------------------------------------------------
  85. // Name: 
  86. // Desc: Structure containing client net configuration data. 
  87. //       The server sends this to clients
  88. //-----------------------------------------------------------------------------
  89. struct  ClientNetConfig
  90. {
  91.     DWORD dwMazeWidth;
  92.     DWORD dwMazeHeight;
  93.     DWORD dwThreadWait;
  94.     WORD  wUpdateRate;
  95.     WORD  wTimeout;
  96.     WORD  wClientPackSizeArray[PACK_ARRAY_SIZE]; //Array of 10 custom sizes passed in by user.
  97.     WORD  wServerPackSizeArray[PACK_ARRAY_SIZE]; //Array of 10 custom server sizes.
  98.     BYTE  ubClientPackIndex;    
  99.     BYTE  ubServerPackIndex;    
  100.  
  101.     BYTE  ubReliableRate;  // Percentage of packets to be transmitted reliably
  102. };
  103.  
  104.  
  105.  
  106.  
  107. //-----------------------------------------------------------------------------
  108. // Name: 
  109. // Desc: Base class for packets sent from server to client
  110. //-----------------------------------------------------------------------------
  111. struct  ServerPacket
  112. {
  113.     ServerPacket();
  114.     ServerPacket( WORD type ) : wType(type) {};
  115.  
  116.     WORD    wType;
  117. };
  118.  
  119.  
  120.  
  121.  
  122. //-----------------------------------------------------------------------------
  123. // Name: 
  124. // Desc: Configuration data send from server to client
  125. //-----------------------------------------------------------------------------
  126. struct  ServerAckVersionPacket : public ServerPacket
  127. {
  128.     ServerAckVersionPacket();
  129.     ServerAckVersionPacket( BOOL accepted, DWORD clientID ) :
  130.         ServerPacket(PACKETTYPE_SERVER_ACKVERSION), bAccepted(accepted), dwClientID(clientID) {};
  131.  
  132.     DWORD dwClientID;
  133.     BOOL bAccepted;
  134. };
  135.  
  136.  
  137.  
  138.  
  139. //-----------------------------------------------------------------------------
  140. // Name: 
  141. // Desc: Configuration data send from server to client
  142. //-----------------------------------------------------------------------------
  143. struct  ServerConfigPacket : public ServerPacket
  144. {
  145.     ServerConfigPacket();
  146.     ServerConfigPacket( const ClientNetConfig& config ) :
  147.         ServerPacket(PACKETTYPE_SERVER_CONFIG) , Config(config) {};
  148.  
  149.     ClientNetConfig Config;
  150. };
  151.  
  152.  
  153.  
  154.  
  155. //-----------------------------------------------------------------------------
  156. // Name: 
  157. // Desc: Chunk of client data for server send to a client
  158. //-----------------------------------------------------------------------------
  159. struct PlayerStatePacket
  160. {
  161.     DWORD   dwID;
  162.     float   fX;
  163.     float   fY;
  164.     ANGLE   aCameraYaw;
  165. };
  166.  
  167.  
  168.  
  169.  
  170. //-----------------------------------------------------------------------------
  171. // Name: 
  172. // Desc: 
  173. //-----------------------------------------------------------------------------
  174. struct  ServerAckPacket : public ServerPacket
  175. {
  176.     ServerAckPacket();
  177.     ServerAckPacket( DWORD playercount )
  178.         : ServerPacket(PACKETTYPE_SERVER_ACKPOS), 
  179.           wPlayerCount(WORD(playercount)) {};
  180.  
  181.     WORD    wPlayerCount;         // Count of total players on server
  182.     WORD    wPlayerStatePacketCount;   // Count of following PlayerStatePacket structures
  183. };
  184.  
  185.  
  186. #pragma pack(pop)
  187.  
  188. #endif
  189.